<?php
include '../include/functions.php';
include 'include/QuickPicks.php';
//set session save path
	session_save_path($session_path);
	// Initialize a session. 
	session_start();
	$count++;
	$sessionId = session_id();
	
	if(!$userID)
	{
		header("Location: logoff.php"); /* Redirect browser */
		/* Make sure that code below does not get executed when we redirect. */
		exit;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 Transitional//EN"
"http://www.w3.org/tr/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/MAIN.dwt.php" codeOutsideHTMLIsLocked="false" -->
  <head>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>JoshHughes.com NFL Football Pool</title>
    <!-- InstanceEndEditable -->
	<link rel="stylesheet" href="../css/football.css" type="text/css">
    <script src="../scripts/prototype.js" type="text/javascript"></script>
	<script src="../scripts/scriptaculous.js" type="text/javascript"></script>
	<script type="text/javascript">
	// Dynamic Iframe loader
	function loadIframe(theFrame, theURL) {
		document.getElementById(theFrame).src=theURL;
	}
	
	// resizes Iframe according to content
	function resizeMe(obj){ 
	docHeight = mainContent.document.body.scrollHeight
	 obj.style.height = docHeight + 'px'
	 } 
	</script>
    <!-- InstanceBeginEditable name="head" -->
		<script language="javascript">
			<!--Combo Box Image Selector
			function showimage()
			{
			if (!document.images)
			return
			document.images.buttons.src= "../images/buttons/" +
			document.updateForm.FavTeam.options[document.updateForm.FavTeam.selectedIndex].value + ".gif"
			document.images.squares.src= "../images/squares/" +
			document.updateForm.FavTeam.options[document.updateForm.FavTeam.selectedIndex].value + ".gif"
			document.images.helmets.src= "../images/helmets/" +
			document.updateForm.FavTeam.options[document.updateForm.FavTeam.selectedIndex].value + ".gif"
			}
			//-->
		</script>
    <!-- InstanceEndEditable -->
  </head>
<body>
<div id="pagewidth" >
	<div id="header" >
	
		<?PHP include_once("layout/header.html"); ?>
		
	</div>
			<div id="wrapper" class="clearfix" > 
			<div id="maincol" >

			<!-- InstanceBeginEditable name="Contents" -->

			<?php
					//Connect To Database
					dbConnect();
					if($Submit) //Update Profile
					{
						if($NFLPool == "yes") {
							$NFLPool = 1;
						} else {
							$NFLPool = 0;
						}
						
						if($AFLPool == "yes") {
							$AFLPool = 1;
						} else {
							$AFLPool = 0;
						}
						//Update Session variables used on other pages...
						$PlayNFL = $NFLPool;
						$PlayAFL = $AFLPool;
							
						//Write SQL to update and change the user's buddy icon
						$SQL = "UPDATE Users SET Username='$Username', Fname='$Fname', LName='$Lname', Email='$Email', Website='$Website', FavTeam='$FavTeam', LogoPref='$LogoPref', NFL=$NFLPool, AFL=$AFLPool WHERE ID=".$userID;
									
						if (mysql_query($SQL))
							echo "<H1>Thank You for modifying your profile</H1>";
						else
							echo "<H3>There seems to have been a problem modifying your profile.  Please go back by selecting the &quot;Edit Profile&quot; link under <i>Preferences:</i> to the left, and try again.</H3>";
					}
					else
					{
						//Write SQL Query to extract specified data
						$SQL = "Select * From Users WHERE (ID=".$userID.")";
						$TeamSQL = "Select DISTINCT TeamName From NFLTeams";
						//Open Record Set using SQL Query
						$result = mysql_query($SQL) or die("Cannot query the database.<br>" . mysql_error());
						//$TeamResult = $result = mysql_query($SQL) or die("Cannot query the database.<br>" . mysql_error());
						?>	
				<table width="500" cellpadding="5" cellspacing="0"> <?
						do
						{
							if (($myrow["Username"] != Null) || ($myrow["Username"] != ""))
							{
								?>
									<tr><td align="center" class="bluebg" height="1"><span class="whitelink">Modify <? echo $myrow["Username"]; ?>'s Profile</span></td></tr>
									<tr><td class="bluebg">
									<form action="<?=$PHP_SELF;?>" method="POST" name="updateForm" enctype="multipart/form-data">
									<input type="hidden" name="MAX_FILE_size" value="15000" />
									<table width="100%" cellspacing="0" cellpadding="3" border="0">
								<?
									echo "<tr bgcolor=\"#FFFFFF\"><td width=\"5%\">&nbsp;</td><td width=\"100\">Username:</td><td><input type=\"text\" name=\"Username\" value=\"".$myrow["Username"]."\" size=\"30\"></td><td width=\"5%\">&nbsp;</td></tr>\n";
									echo "<tr bgcolor=\"#FFFFFF\"><td width=\"5%\">&nbsp;</td><td>First Name:</td><td><input type=\"text\" name=\"Fname\" value=\"".$myrow["Fname"]."\" size=\"30\"></td><td width=\"5%\">&nbsp;</td></tr>\n";
									echo "<tr bgcolor=\"#FFFFFF\"><td width=\"5%\">&nbsp;</td><td>Last Name:</td><td><input type=\"text\" name=\"Lname\" value=\"".$myrow["Lname"]."\" size=\"30\"></td><td width=\"5%\">&nbsp;</td></tr>\n";
									echo "<tr bgcolor=\"#FFFFFF\"><td width=\"5%\">&nbsp;</td><td>Email Address:</td><td><input type=\"text\" name=\"Email\" value=\"".$myrow["Email"]."\" size=\"30\"> <a href=\"#email\">Email Prefs</a></td><td width=\"5%\">&nbsp;</td></tr>\n";
									echo "<tr bgcolor=\"#FFFFFF\"><td width=\"5%\">&nbsp;</td><td>Website:</td><td><input type=\"text\" name=\"Website\" value=\"".$myrow["Website"]."\" size=\"30\"></td><td width=\"5%\">&nbsp;</td></tr>\n";
									echo "<tr bgcolor=\"#FFFFFF\"><td width=\"5%\">&nbsp;</td><td>Favorite Team:</td><td><select name=\"FavTeam\" onChange=\"showimage()\">";
									$TeamResult = mysql_query($TeamSQL) or die("Cannot query the database.<br>" . mysql_error());		
									do
									{
										if($Teamrow["TeamName"] != "")
										{
											if ($Teamrow["TeamName"] == $myrow["FavTeam"])
											{
												echo "<option value=\"".$Teamrow["TeamName"]."\" selected>".$Teamrow["TeamName"]."</option>";
											} 
											else
											{
												echo "<option value=\"".$Teamrow["TeamName"]."\">".$Teamrow["TeamName"]."</option>";
											}
										}
									}while($Teamrow = mysql_fetch_array($TeamResult));
									echo "</select></td><td width=\"5%\">&nbsp;</td></tr>";
								?>
								<tr bgcolor="#FFFFFF">
									<td height="25" colspan="4">
										<table>
										   <tr>
											<td valign="Bottom" width="33%"><input type="radio" name="LogoPref" id="LogoPref" value="buttons" <? if($myrow["LogoPref"] == "buttons") {echo "checked";}?>>Round Logo</td>
											<td valign="Bottom" width="33%"><input type="radio" name="LogoPref" id="LogoPref" value="squares" <? if($myrow["LogoPref"] == "squares") {echo "checked";}?>>Square Logo</td>
											<td valign="Bottom" width="34%"><input type="radio" name="LogoPref" id="LogoPref" value="helmets" <? if($myrow["LogoPref"] == "helmets") {echo "checked";}?>>Helmet Logo</td>
							
										   </tr>
										   <tr>
											<td valign="middle"><img src="../images/buttons/<?=$myrow["FavTeam"];?>.gif" name="buttons" ></td>
											<td valign="middle"><img src="../images/squares/<?=$myrow["FavTeam"];?>.gif" name="squares" ></td>
											<td valign="middle"><img src="../images/helmets/<?=$myrow["FavTeam"];?>.gif" name="helmets" ></td>
										   </tr>
										</table>
									</td>
								</tr>
								<?
								// Play in NFL Pool optin
								echo "\n<tr bgcolor=\"#FFFFFF\"><td width=\"5%\">&nbsp;</td><td>Play NFL:</td><td><input name=\"NFLPool\" type=\"Checkbox\" id=\"NFLPool\" value=\"yes\" ";
								if($myrow["NFL"] == 1) { echo "Checked"; }
								echo " /></td><td width=\"5%\">&nbsp;</td></tr>\n";
								echo "<tr bgcolor=\"#FFFFFF\"><td width=\"5%\">&nbsp;</td><td>Play AFL:</td><td><input name=\"AFLPool\" type=\"Checkbox\" id=\"AFLPool\" value=\"yes\" ";
								if($myrow["AFL"] == 1) { echo "Checked"; }
								echo " /></td><td width=\"5%\">&nbsp;</td></tr>\n";
								
							}//end if (($myrow["username"] != Null...
						}while($myrow = mysql_fetch_array($result));
						?>
							<tr bgcolor="#FFFFFF"><td colspan="4" align="center"><input type="submit" name="Submit" id="Submit" value="Submit Changes"></td></tr><tr bgcolor="#FFFFFF"><td colspan="4">&nbsp;</td></tr>
							</table></Form></td></tr></table>
							<br/> 
						<!--
							<table width="500" cellpadding="5" cellspacing="0">
							<tr>
							<td class="bluebg" align="Left"><span class="whitelink">Pool Feature Options</span></td>
							  </tr>
								<td class="bluebg" align="Left">
								<form name="featureForm" action="<?=$PHP_SELF;?>" method="POST">
								   <table width="100%" border="0" cellspacing="0" cellpadding="0" border="0" bgcolor="#FFFFFF">
									<tr>
										<td width="3%">&nbsp;</td>
												<td height="25">
										<B>Quick Picks:</B>
										</td>
										<td height="25">
										<?
										/*
										if(IsQPEnabled($userID))
											echo "Quick Picks are currently <b>Enabled</b>.</td><td><input type=\"submit\" name=\"QP\" value=\"Disable Quick Picks\">"; 
										else
											echo "Quick Picks are currently <b>Disabled</b>.</td><td><input type=\"submit\" name=\"QP\" value=\"Enable Quick Picks\">"; 
										*/
										?>
										</td>
										<td width="3%">&nbsp;</td>
									</tr>
									</table>
								 </form>
								</td>
							  </tr>
							</table>
						-->
						<?
						//Update user Email Preferences
						$SQL = "SELECT ShowEmail, RemindMe, TuesdayEmail, EmailPicks FROM NFLUsers WHERE ID = $userID";
						$IDresult = mysql_query($SQL) or die("Cannot query the database.<br>" . mysql_error());
						$IDrow = mysql_fetch_array($IDresult);
						 ?>
							<br/>
							<table width="500" cellpadding="5" cellspacing="0">
							<tr>
							<td class="bluebg" align="Left"><span class="whitelink">Change Email Preferences</span></td>
							  </tr>
								<td class="bluebg" align="Left">
								<form name="emailPrefForm" action="change.php" method="POST">
								   <table width="100%" border="0" cellspacing="0" cellpadding="0" border="0" bgcolor="#FFFFFF">
									<tr>
										<td width="5%"><a name="email">&nbsp;</a></td>
												<td height="25">
										<B>Keep Email Address Private:</B>
										</td>
												<td height="25">
										<input name="ShowEmail" type="Checkbox" id="ShowEmail" value="yes" <?
										if($IDrow["ShowEmail"] == 0) { echo "checked"; }
										?>>
										</td>
										<td width="5%">&nbsp;</td>
									</tr>
									<tr bgcolor="#EEEEEE">
										<td width="5%">&nbsp;</td>
												<td height="25">
										<B>Remind me when I need to make picks</B>
										</td>
												<td height="25">
										<input name="RemindMe" type="Checkbox" id="RemindMe" value="yes" <?
										if($IDrow["RemindMe"] == 1) { echo "checked"; }
										?>>
										</td>
										<td width="5%">&nbsp;</td>
									</tr>
									<tr>
										<td width="5%">&nbsp;</td>
												<td height="25">
										<B>Send me weekly score updates on Tuesdays</B>
										</td>
												<td height="25">
										<input name="TuesdayEmail" type="Checkbox" id="TuesdayEmail" value="yes" <?
										if($IDrow["TuesdayEmail"] == 1) { echo "checked"; }
										?>>
										</td>
										<td width="5%">&nbsp;</td>
									</tr>
									<tr bgcolor="#EEEEEE">
										<td width="5%">&nbsp;</td>
												<td height="25">
										<B>Send me user's picks shortly after games begin.</B>
										</td>
												<td height="25">
										<input name="EmailPicks" type="Checkbox" id="EmailPicks" value="yes" <?
										if($IDrow["EmailPicks"] == 1) { echo "checked"; }
										?>>
										</td>
										<td width="5%">&nbsp;</td>
									</tr>
									<tr> 
										<td width="5%">&nbsp;</td>
												<td height="25" colspan="2"><div align="center"> 
										<input type="submit" name="Submit" value="Change Preferences">
										<input type="reset" name="Submit2" value="Reset Form"></div>
										</td>
										<td width="5%">&nbsp;</td>
									</tr>
		    </table>
								 </form>
								</td>
							  </tr>
							</table>
								 <?
					}//end if($Submit)
			?>

			<!-- InstanceEndEditable -->
			
			</div>
			<div id="leftcol" >
			
				<?PHP include_once("layout/left_column.php"); ?>
		
			</div>
			
		</div>
		
		<div id="footer" >
		
			<?PHP include_once("layout/footer.html"); ?>
			
		</div>
</div>
</body>
<!-- InstanceEnd --></html>